<?php
	session_start();
	include 'ref.php';
	
	if (!isset($_SESSION['nowa'])) {
		session_regenerate_id();
		$_SESSION['block'] = false;
		$_SESSION['nowa'] = true;
		$_SESSION['adresuzytkownika'] = $_SERVER['REMOTE_ADDR'];
	}

	if($_SESSION['adresuzytkownika'] != $_SERVER['REMOTE_ADDR']) {
		session_destroy();
	}
	error_reporting(E_ALL & ~E_NOTICE);
	if(isset($_SESSION['zalogowany']) && $_SESSION['zalogowany']==true) {
		//--------------------------------------------------------------------------------------------------------
        header("Content-type: text/xml");
        $lectureId = $_GET['element'];
       
		require_once 'dbConnection.php';

		$db_result = mssql_query("EXECUTE GetCwiczenia $lectureId");
        $xml = '<?xml version="1.0" encoding="utf-8"?><gr>';
        while($row = mssql_fetch_array($db_result)) {
			$id = $row['id'];
			$dzien = $row['dzien'];
			$godz = $row['godz_rozp'];
            $xml=$xml. '<grZajeciowa>
                            <godz_rozp>'.$godz.'</godz_rozp>
                            <dzien>'.$dzien.'</dzien>
                            <id>'.$id.'</id>
                        </grZajeciowa>';
                
               		
		}
        $xml =$xml.'</gr>';
        echo $xml;
        
		mssql_free_result($db_result);
		mssql_close($con);
		//--------------------------------------------------------------------------------------------------------
	}
	else {
		header("Location: logowanie.php");
		exit;
	}
?>
